#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <vector>
#include <stack>
using namespace std;
void image(vector<vector<int>>& vv)
{
    int l = 0, r = vv[0].size() - 1;
    while (l < r)
    {
        for (int i = 0;i < vv.size();i++)
        {
            swap(vv[l][i], vv[r][i]);
        }
        ++l;
        --r;
    }
}
void rotate(vector<vector<int>>& vv)
{
    vector<vector<int>> tmp(vv.size(), vector<int>(vv[0].size(), 0));
    for (int i = tmp.size() - 1;i >= 0;i--)
    {
        for (int j = tmp[i].size();j >= 0;j--)
        {
            tmp[vv.size() - i - 1][vv[0].size() - j - 1] = vv[i][j];
        }
    }
    vv = tmp;
}
int main()
{
    int n = 0;
    cin >> n;
    cerr << "n=" << n << endl;
    vector<vector<int>> vv(n, vector<int>(n, 0));
    for (int i = 0;i < n;i++)
    {
        for (int j = 0;j < n;j++)
        {
            cin >> vv[i][j];
        }
    }
    int q;
    cin >> q;
    int x = 0;
    stack<int> st;
    while (q--)
    {
        cin >> x;
        if (st.empty()) st.push(x);
        else
        {
            int t = st.top();
            if (x == t) st.pop();
            else st.push(x);
        }
    }
    vector<int> op(st.size(), 0);
    for (int i = op.size() - 1;i >= 0;i--)
    {
        op[i] = st.top();
        st.pop();
    }
    // cout<<"op: "; 
    // for(auto a:op)cout<<a<<" ";
    // cout<<endl;
    for (int i = 0;i < op.size();i++)
    {
        if (op[i] == 1) rotate(vv);
        else if (op[i] == 2) image(vv);
    }
    for (auto a : vv)
    {
        for (auto b : a)
        {
            cout << b << " ";
        }
        cout << endl;
    }
    return 0;
}